﻿package  restless.core.gameObjs {
	
	import com.greensock.data.TweenMaxVars;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import restless.core.interfaces.iMenu;
	import restless.core.managers.RLERender;
	import restless.menu.Menu;
	
	
	/**
	 * 
	 * @author Jordan Laine
	 * 
	 */
	
	public class RLEButton extends RLEMenuObj {
		protected var nOffSetX:Number = 0;
		protected var nOffSetY:Number = 0;
		
		protected var sOverMC:String;
		protected var sOutMC:String;
		
		
		public function RLEButton (menu:iMenu) {
			setRE();
			mousePriority = 5;
			super(menu);
		}
		
		public function move(toX:Number, toY:Number, fromX:Number = NaN, fromY:Number = NaN, frames:Number = 30):void {
			tempPoint.x = (isNaN(fromX) ) ? this.x : fromX;
			tempPoint.y = (isNaN(fromY) ) ? this.y : fromY;
			tween = TweenMax.fromTo( this, frames, { x:tempPoint.x, y:tempPoint.y }, { x:toX, y:toY, onComplete:test, onCompleteParams:[true], useFrames:true } );
		}
		
		public function over():void {
			if (nCurrentFrame == 1) { return; }
			nCurrentFrame = 1;
			forceRender();
		}
		
		public function out():void {
			if (nCurrentFrame == 2) { return; }
			nCurrentFrame = 2;
			forceRender();
		}
		
		private function test(bool:Boolean):void {
			activate = bool;
		}
		
		override public function set activate(bool:Boolean):void {
			if (bool == bActivate) { return; }
			bActivate = bool;
			updating = bActivate;
			shouldItLeftClick(bActivate);
			shouldItRightClick(bActivate);
			shouldItMouseOver(bActivate);
			shouldItTween(bActivate);
			visible = bActivate;
			i = vTextObjs.length - 1;
			if (i > -1) {
				for (i; i > -1; i--) {
					vTextObjs[i].updating = bActivate;
					vTextObjs[i].visible = bActivate;
				}
			}
		}
		
		override public function mClickL():void {
			//
			// click functionality in parent menu
			//
			parentMenu.click(nID);			
		}
		
		override public function mClickR():void {
			//
			// click functionality in parent menu
			//
			parentMenu.click(nID);			
		}
		
		override public function mOver():void {
			parentMenu.deselectButtons();
			parentMenu.selectedBtn = nID;
			parentMenu.updateButtons();
			over();
		}
		
		override public function mOut():void {
			out();
			parentMenu.deselectButtons();
		}
		
		public function animateOut():void {
			
		}
		
		public function setOffSet(x:Number, y:Number):void {
			this.x += nOffSetX;
			this.y += nOffSetY;
		}
		
		override public function dispose():void {
			tween.kill();
			super.dispose();
		}
	}
}